﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;

namespace Component
{
    public class UsersDB:Base
    {
        public static Users TestLogin(string userName, string pass)
        {
            XPCollection<Users> _xpUser = new XPCollection<Users>(KetNoiCSDL.session);

            Users users = KetNoiCSDL.session.FindObject<Users>(DevExpress.Data.Filtering.CriteriaOperator.Parse
                ("User_name==? and Pass==?", ConvertType.EncodePassword(userName), ConvertType.EncodePassword(pass)));
            if (users != null)
            {
                return users;
            }
            return null;
        }
        /// <summary>
        /// GetMenuById(int id)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Users GetObjectById(int id)
        {
            return KetNoiCSDL.session.FindObject<Users>(DevExpress.Data.Filtering.CriteriaOperator.Parse("Id=" + id.ToString()));
        }
        public static Users GetObjectById()
        {
            XPCollection<Users> _xpUser = new XPCollection<Users>(KetNoiCSDL.session);
            _xpUser.Filter = null;
            return _xpUser[0];
        }
    }
}
